package com.kocla.mz.accountdemo;

import android.accounts.Account;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.kocla.mz.accountdemo.account.AccountHelper;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AccountHelper.initialize(this);
    }

    public void getAccount(View view) {
        if (AccountHelper.hasAccount(this)) {
            Account account = AccountHelper.getCurrentAccount(this);
            String actionText = "确定";
            String msg = "Name: " + account.name + " \nPwd: " + AccountHelper.getAccountPassword(account) + "    token: " + AccountHelper.getCurrentToken(this);
            Snackbar.make(view, msg, Snackbar.LENGTH_LONG)
                    .setAction(actionText, null)
                    .show();
        } else {
            String msg = "No Account";
            String actionText = "确定";
            Snackbar.make(view, msg, Snackbar.LENGTH_LONG)
                    .setAction(actionText, null)
                    .show();
        }


    }

    public void addAccount(View view) {
        AccountHelper.addAccount(this, "tom", "1234", "token2sjkigo");
        Snackbar.make(view, "添加成功", Snackbar.LENGTH_LONG)
                .setAction("确定", null)
                .show();
    }

    public void clearAccount(final View view) {
        AccountHelper.clearAccounts(this, new AccountHelper.OnAccountListener() {
            @Override
            public void onFinished() {
                Snackbar.make(view, "删除成功", Snackbar.LENGTH_LONG)
                        .setAction("确定", null)
                        .show();
            }
        });
    }
}
